package com.ikangtai.shecare.common;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.MotionEvent;

import com.bugtags.library.Bugtags;
import com.ikangtai.shecare.R;
import com.ikangtai.shecare.common.util.AppLog;
import com.ikangtai.shecare.main.MainActivity;
import com.jaeger.library.StatusBarUtil;
import com.umeng.analytics.MobclickAgent;

public class BaseActivityWithoutS extends FragmentActivity  {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // appKilledFlag 为 -1 说明程序被杀掉
        if(App.appKilledFlag == -1){
            AppLog.i("shecare is killed by Android OS! now begin reStart!");
            protectApp();
        }else
            AppLog.i("shecare normally start!");

        App.activityList.add(this);
    }

    protected void protectApp() {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//清空栈里MainActivity之上的所有activty
        startActivity(intent);
        finish();
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        setStatusBar();
    }

    protected void setStatusBar() {
        StatusBarUtil.setColor(this, getResources().getColor(R.color.orange), 0);
    }


    @Override
    protected void onResume() {
        super.onResume();
        //注：回调 1
        Bugtags.onResume(this);
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        //注：回调 2
        Bugtags.onPause(this);
        MobclickAgent.onPause(this);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        //注：回调 3
        Bugtags.onDispatchTouchEvent(this, event);
        return super.dispatchTouchEvent(event);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        App.activityList.remove(this);
    }
}

